import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

import '../../../../base/utils/logger.dart';
import '../../../../data/api.dart';
import '../../../../data/models/get_info_res.dart';
import '../../../../main_service.dart';

class MinePageController extends GetxController {
  //TODO: Implement MinePageController

  final count = 0.obs;
  @override
  void onInit() {
    super.onInit();
    getUserInfo();
  }

  UserInfo? userInfo;

  @override
  void onReady() {
    super.onReady();

  }

  @override
  void onClose() {
    super.onClose();
  }

  void increment() => count.value++;

  getUserInfo()async{
    try {
      EasyLoading.show();
      UserInfo? userInfo = await Api.getUserInfo();
      this.userInfo = userInfo;
      if (userInfo != null) {
        Get.find<MainService>().userInfo = userInfo!;
      }
    } catch (e) {
      loggy.error(e);
    }finally{
      EasyLoading.dismiss();
    }
  }

  get userName => userInfo?.username??'';
  get nickName => userInfo?.nickname??'';
  get avatar => userInfo?.avatar??'';
  get  mobile => userInfo?.mobile??'';

}
